//
//  NVActivityIndicatorView+Rx.swift
//  Candy
//
//  Created by Insect on 2019/5/20.
//  Copyright © 2019 Insect. All rights reserved.
//

import Foundation
import MBProgressHUD
import NSObject_Rx
import RxCocoa
import RxSwift
class HUDManager {
    static let shared = HUDManager()

    var hud: MBProgressHUD?
}

extension Reactive where Base: UIViewController {

    public var isAnimating: Binder<Bool> {
        return Binder(self.base) { vc, active in
            if active {
                HUDManager.shared.hud = HUD.showLoading()
            } else {
                HUDManager.shared.hud?.hide(animated: true)
            }
        }
    }
}

extension Reactive where Base: UIView {

    public var isAnimating: Binder<Bool> {
        return Binder(self.base) { view, active in
            if active {
                HUDManager.shared.hud = HUD.showLoading()
            } else {
                HUDManager.shared.hud?.hide(animated: true)
            }
        }
    }
}
